<?php
class Singleton
{
    static protected $_instance;
    /** @return self */
    static public function instance()
    {
        if(!static::$_instance) static::$_instance = new static;
        return static::$_instance;
    }

    public $id="";
    public function __construct()
    {
        if(self::$_instance){
            throw new Error("重复创建单例对象");
            exit;
        }
        $this->id=rand(100000,999999);
    }
    public function say()
    {
        echo $this->id ."\r\n";
    }
}

header('Content-Type: text/plain');

Singleton::instance()->say();
Singleton::instance()->say();
(new Singleton())->say();
